﻿using System;
using System.Collections.Generic;

namespace Pixels.Logic.Rules
{
    public class FoodAndStarvation : LogicRule {
        internal override void execute() {
            var numApples = World.Colony.accumulatedResources[Resource.Apples];
            var numColonists = World.Colony.allColonists.Count;
            if (numApples < numColonists) {

                World.Colony.accumulatedResources.changeResource(Resource.Apples, -numApples); // should drop to zero
                var difference = numColonists - numApples;// -numColonists;
                var starved = Ur.Maths.floor(difference * 0.5f + 1f); // ceiling of half                 
                World.Logic.injectEvent(new GameplayEvents.StarvationEvent(starved));

            } else {

                World.Colony.accumulatedResources.changeResource(Resource.Apples, -numColonists);

            }
        }
    }
}
